<template>
     <div ref="pages">
      <span class="news-text">{{titleName}}</span>       
      <a-divider style="margin-top:20px;margin-bottom:20px;" />       
      <div class="report-search-div" v-if="isShowQuery">
         <a-form-model layout="inline" :model="form" ref="formModal" :rules="rules">
            <a-form-model-item prop="queryinput">
              <a-input v-model="form.queryinput" placeholder="请输入办件手机号" allow-clear style="font-size:14px;width:260px;"/>
            </a-form-model-item> 
            <a-form-model-item prop="code"  style="width:260px;">
              <a-input v-model="form.code" allow-clear placeholder="请输入验证码" >
                <valid-code slot="addonAfter" :value.sync="validCode" @input="getValidCode" :width="'60px'" :height="'39px'"></valid-code>
              </a-input>
            </a-form-model-item>
            <a-form-model-item>
              <a-button type="primary" class="report-search-btn" @click="queryTable">查询</a-button>
            </a-form-model-item>
         </a-form-model>
       </div>  
      <div class="unit-table-div">
          <CustomTable
            :onRowClick="onDetail"
            ref="table"
            :showAlert="false"
            :showSelection="false"
            :columns="columns"
            :loading="load"
            @change="onTableChange"
            :dataSource="pageData"
            rowKey="id"
          >
            <template slot="xh" slot-scope="text, record, index">
              {{((pageFilter.pageNo - 1) * pageFilter.pageSize +(index + 1))>9?(pageFilter.pageNo - 1) * pageFilter.pageSize +(index + 1) :'0' + (index + 1) }}
            </template>
          </CustomTable>
      </div>
    </div>
</template>

<script>
// import moment from "moment";
import emv from "@/views/center/emptyVue.vue";
import validCode from '@/components/ValidCode';
import { phoneValidata} from "@/utils/common";
import api from '@/api/index'
  export default {
    name: "reportlist",
    components: {
       validCode
    },
    props: {
      page: {
        type: String,
        default: '1'
      },
    },
     data(){
       let validateCode = (rule, value, callback) => {
          if (value === '' || value === null || value===undefined) {
            callback(new Error('请输入验证码'));
          } else if (value.toLowerCase().trim()!=this.validCode.toLowerCase().trim()) {
            callback(new Error("验证码输入错误！"));
          } else {
            callback();
          }
        };
      return{
        clientHeight:'',
        screenHeight:'',
        pageName:"bjqkgkPage",
        titleName:"办件情况公开",
        load: false,
        isShowQuery:false,
        validCode:'',
        form: {},
        rules: {
          queryinput: [
            { required: true, message: "请输入手机号" },
            {
              validator: phoneValidata
            }
          ],
          code: [{validator: validateCode, trigger: 'change' }],//[{ required: true, message: "请输入" }],
        },
        columns: [
          {
              title: '序号',
              dataIndex: 'xh',
              key: 'xh',
              width:80,
              scopedSlots: { customRender: "xh" }
            },
            {
              title: '标题',
              dataIndex: 'title',
              key: 'title',
              ellipsis: true,
            },
            {
              title: '状态',
              dataIndex: 'processStatus',
              key: 'processStatus',
              ellipsis: true,
            },
            {
              title: '受理时间',
              dataIndex: 'awsTime',
              key: 'awsTime',
              ellipsis: true,
            },
            
        ],
        pageData: [
           
        ],
        pageFilter: {
          idPublic:true,
          pageNo: 1,
          pageSize: 10
        }
      }
      
    },
    mounted(){
      this.setFootStyle();     
    },
    methods: {
      itemRender(current, type, originalElement) {
        if (type === 'prev') {
          return <a><i aria-label="图标: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>上一页</a>;
        } else if (type === 'next') {
          return <a>下一页<i aria-label="图标: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a>;
        }
        return originalElement;
      },
      getScreenHeight(){
        // 获取浏览器可视区域高度
        this.screenHeight =    document.body.clientHeight ; //`${document.documentElement.clientHeight}` 
        window.onresize = function temp() {
          this.screenHeight = document.body.clientHeight;
        };
      },
      setPage(pageName,titleName){
        this.pageName = pageName;
        this.titleName = titleName;
        if(pageName=='bjqkgkPage'){//办件情况公开
          this.isShowQuery = false;
          this.pageFilter={
            idPublic:1,
            pageNo: 1,
            pageSize: 10
          }
          this.refreshTable_public();
        }else if(pageName=='wycxPage'){//办件查询
          this.isShowQuery = true;
          this.pageData={};
        }
      },
      onTableChange(pageFilter) {
         this.pageFilter = { ...this.pageFilter, ...pageFilter };
         this.refreshTable();
         
      },
      refreshTable(){
        if(this.pageName == 'bjqkgkPage'){
          this.refreshTable_public();
        }else if(this.pageName == 'wycxPage'){
           this.refreshTable_personal();
        }
      },
      async refreshTable_public() {
         this.load = true;
         await api .get_report_public_list(this.pageFilter) .then(res => {
          let pageNo = this.pageFilter.pageNo;
          let pageSize = this.pageFilter.pageSize;
          let records = res.rows;
          let total = res.total;
          this.pageData = {
            ...this.pageData,
            pageNo,
            records,
            pageSize,
            total
          };
          this.load = false;
            
        })
        .catch(err => {
          this.load = false;
        });

        this.setFootStyle();
      },
      async refreshTable_personal() {
         this.load = true;
         await api .get_report_personal_list(this.pageFilter) .then(res => {
          let pageNo = this.pageFilter.pageNo;
          let pageSize = this.pageFilter.pageSize;
          let records = res.rows;
          let total = res.total;
          this.pageData = {
            ...this.pageData,
            pageNo,
            records,
            pageSize,
            total
          };
          this.load = false;
            
        })
        .catch(err => {
          this.load = false;
        });

        this.setFootStyle();
      },
      onDetail(record){
     
          this.$router.push({
              name:"detailReport",
              pageName:this.pageName,
              query:{
                type:'detail',
                id:record.id,
                status:record.statusId,
                breadcrumbName:'举报投诉'

             }
            });
          
        },
      getValidCode(code){
        this.validCode = code;
      },
      queryTable(){
        this.$refs.formModal.validate(valid => {
        if (valid) {
          this.pageFilter={
            pageNo: 1,
            pageSize: 10,
            phone:this.form.queryinput,
          }
          this.refreshTable_personal();
        }
      });

        
      },
      setFootStyle(){
        this.$nextTick(()=>{ // 页面渲染完成后的回调
                  this.getScreenHeight();
                  this.clientHeight = this.$refs.pages.offsetHeight+364;
                  // console.log(this.screenHeight,this.clientHeight);
                  if(this.screenHeight>this.clientHeight){
                    if(this.screenHeight-this.clientHeight>30){
                      emv.$emit("setfootmargintop",this.screenHeight-this.clientHeight);
                    }else{
                       emv.$emit("setfootmargintop",30);
                    }
                  }else{
                    emv.$emit("setfootmargintop",30);
                  }
                 
          });
      }
   },
   beforeRouteEnter(to, from, next) {
      // 设置下一个路由的 meta
       next(vm=>{
            vm.setPage(to.name, to.meta.title);
            emv.$emit("setMenuKey",to.meta.mkey);
         })
    },
  };
</script>
<style lang="less">
.news-text{
  font-size: 26px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #337BD7;
}

.unit-table-div{
  margin-left: -10px;
  .ant-table-thead > tr > th {
    padding: 16px 16px;
    overflow-wrap: break-word;
    font-size: 16px;
  }
  .ant-table-tbody > tr > td {
      padding: 16px 16px;
      overflow-wrap: break-word;
      font-size: 14px;
  }
}

.report-search-div{
  width:100%;
  display:flex;
  margin-bottom: 20px;
  .report-search-btn{
    // width: 80px;
    height: 40px;
    background: #337bd7;
    border: 0;
    border-radius: 4px;
    margin-left: 10px;
    margin-top: 1px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #FFFFFF;
  }
  .ant-btn-primary:hover, .ant-btn-primary:focus {
    color: #fff;
    background-color: #337BD7;
    border-color: #337BD7;
  }
   .ant-input-affix-wrapper .ant-input {
    position: relative;
    text-align: inherit;
    height: 41px;
  }
}
</style>